home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
tuner
/
tuner_sl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
123 lines
/***********************************************************
Copyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
Netherlands.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Socket-related subroutines shared by broadcast and radio */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include "tuner.h"
#define MSG_BUFSIZE 128 /* Message size */
int
opensock()
{
int s;
int on = 1;
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
perror("socket()");
exit(1);
}
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST,
&on, sizeof (on)) < 0) {
perror("setsockopt(SO_BROADCAST)");
exit(1);
}
return s;
}
int
openscsock()
{
int s;
int on = 1;
struct sockaddr_in sin;
s = socket(AF_INET, SOCK_DGRAM, 0);
#ifdef SO_REUSEPORT
(void)setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on));
#endif
bzero((char *)&sin, sizeof sin);
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_family = AF_INET;
sin.sin_port = htons(CTLPRT_SCALL);
if ( bind(s, &sin, sizeof sin) < 0) {
perror("bind(stationcallsocket)");
exit(1);
}
return s;
}
char *
recvsock(s)
int s;
{
fd_set fdset;
int rv;
struct timeval tv;
static char buf[MSG_BUFSIZE];
FD_ZERO(&fdset);
FD_SET(s, &fdset);
tv.tv_sec = WAIT_TIMEOUT;
tv.tv_usec = 0;
if( (rv = select(s+1, &fdset, (fd_set *)0, (fd_set *)0, &tv)) < 0 ) {
perror("select(socket)");
exit(1);
}
if ( rv == 0 )
return NULL;
if ( (rv=recv(s, buf, sizeof(buf), 0)) < 0 ) {
perror("recv()");
exit(1);
}
buf[rv] = 0;
return buf;
}
void
sendsock(s, to, msg)
int s;
struct sockaddr_in *to;
char *msg;
{
if ( sendto(s, msg, strlen(msg), 0, to, sizeof(*to)) < 0 ) {
perror("sendto()");
exit(1);
}
}